package com.dusk.util
{
	
	import flash.filters.BevelFilter;
	import flash.filters.BlurFilter;
	import flash.filters.DropShadowFilter;
	import flash.filters.GlowFilter;
	import flash.filters.GradientBevelFilter;
	import flash.filters.GradientGlowFilter;
	
	public final class FilterUtil extends UtilBase
	{
		
		private static var _filters:Array = [];
		
		public function FilterUtil():void
		{
		}
		
		//设置投影滤镜
		public static function setDropShadow(mc:*, distance:Number = 4.0, angle:Number = 45, color:uint = 0, alpha:Number = 1.0, blurX:Number = 4.0, blurY:Number = 4.0, strength:Number = 1.0, quality:int = 1, inner:Boolean = false, knockout:Boolean = false, hideObject:Boolean = false):void
		{
			//阴影的偏移距离，以像素为单位|阴影的角度|阴影的颜色|阴影颜色的 Alpha 透明度值|水平模糊量|垂直模糊量|印记或跨页的强度|应用滤镜的次数|表示阴影是否为内侧阴影|应用挖空效果 (true)，这将有效地使对象的填色变为透明，并显示文档的背景颜色|表示是否隐藏对象
			var drop:DropShadowFilter = new DropShadowFilter(distance, angle, color, alpha, blurX, blurY, strength, quality, inner, knockout, hideObject);
			_filters.push(drop);
			
			mc.filters = ArrayUtil.filterKeepOne(_filters);
		}
		
		//设置模糊滤镜
		public static function setBlur(mc:*, blurX:Number = 4.0, blurY:Number = 4.0, quality:int = 1):void
		{
			//水平模糊量|垂直模糊量|执行模糊的次数
			var blur:BlurFilter = new BlurFilter(blurX, blurY, quality);
			_filters.push(blur);
			
			mc.filters = ArrayUtil.filterKeepOne(_filters);
		}
		
		//设置发光滤镜
		public static function setGlow(mc:*, color:uint = 0xFF0000, alpha:Number = 1.0, blurX:Number = 6.0, blurY:Number = 6.0, strength:Number = 2, quality:int = 1, inner:Boolean = false, knockout:Boolean = false):void
		{
			//光晕颜色|颜色的 Alpha 透明度值|水平模糊量|垂直模糊量|印记或跨页的强度|应用滤镜的次数|指定发光是否为内侧发光|指定对象是否具有挖空效果
			var glow:GlowFilter = new GlowFilter(color, alpha, blurX, blurY, strength, quality, inner, knockout);
			_filters.push(glow);
			
			mc.filters = ArrayUtil.filterKeepOne(_filters);
		}
		
		//设置斜角滤镜
		public static function setBevel(mc:*, distance:Number = 4.0, angle:Number = 45, highlightColor:uint = 0xFFFFFF, highlightAlpha:Number = 1.0, shadowColor:uint = 0x000000, shadowAlpha:Number = 1.0, blurX:Number = 4.0, blurY:Number = 4.0, strength:Number = 1, quality:int = 1, type:String = "inner", knockout:Boolean = false):void
		{
			//斜角的偏移距离|斜角的角度|斜角的加亮颜色|加亮颜色的 Alpha 透明度值|斜角的阴影颜色|阴影颜色的 Alpha 透明度值|水平模糊量，以像素为单位|垂直模糊量，以像素为单位|印记或跨页的强度|应用滤镜的次数|斜角在对象上的位置|应用挖空效果 (true)，这将有效地使对象的填色变为透明，并显示文档的背景颜色
			var bevel:BevelFilter = new BevelFilter(distance, angle, highlightColor, highlightAlpha, shadowColor, shadowAlpha, blurX, blurY, strength, quality, type, knockout);
			_filters.push(bevel);
			
			mc.filters = ArrayUtil.filterKeepOne(_filters);
		}
		
		//设置渐变斜角滤镜
		public static function setGradientBevel(mc:*, distance:Number = 4.0, angle:Number = 45, colors:Array = null, alphas:Array = null, ratios:Array = null, blurX:Number = 4.0, blurY:Number = 4.0, strength:Number = 1, quality:int = 1, type:String = "inner", knockout:Boolean = false):void
		{
			//偏移距离|角度，以度为单位|渐变中使用的 RGB 十六进制颜色值数组|colors 数组中对应颜色的 Alpha 透明度值的数组|对应于 colors 数组中颜色的一组颜色分布比率|水平模糊量，以像素为单位|垂直模糊量，以像素为单位|印记或跨页的强度|应用滤镜的次数|斜角效果的放置|指定对象是否具有挖空效果
			var gradientBevel:GradientBevelFilter = new GradientBevelFilter(distance, angle, colors, alphas, ratios, blurX, blurY, strength, quality, type, knockout);
			_filters.push(gradientBevel);
			
			mc.filters = ArrayUtil.filterKeepOne(_filters);
		}
		
		//设置渐变发光滤镜
		public static function setGradientGlow(mc:*, distance:Number = 4.0, angle:Number = 45, colors:Array = null, alphas:Array = null, ratios:Array = null, blurX:Number = 4.0, blurY:Number = 4.0, strength:Number = 1, quality:int = 1, type:String = "inner", knockout:Boolean = false):void
		{
			//光晕的偏移距离|角度，以度为单位|定义渐变的颜色数组|colors 数组中对应颜色的 Alpha 透明度值的数组|对应于 colors 数组中颜色的一组颜色分布比率|水平模糊量，以像素为单位|垂直模糊量，以像素为单位|印记或跨页的强度|应用滤镜的次数|斜角在对象上的位置|应用挖空效果 (true)，这将有效地使对象的填色变为透明，并显示文档的背景颜色
			var gradientGlow:GradientGlowFilter = new GradientGlowFilter(distance, angle, colors, alphas, ratios, blurX, blurY, strength, quality, type, knockout);
			_filters.push(gradientGlow);
			
			mc.filters = ArrayUtil.filterKeepOne(_filters);
		}
		
		/*
		//设置调整颜色滤镜
		public static function setColorMatrix(mc:*,):void{
				var colorMatrix:ColorMatrixFilter=new ColorMatrixFilter();
		}*/
		
		//清理缓存的滤镜信息
		public static function clearCache():void
		{
			_filters = [];
		}
		
		//删除指定mc的所有滤镜
		public static function deleteAllFilters(mc:*):void
		{
			mc.filters = null;
		}
		
		//获取指定mc的全部滤镜属性
		public static function getFilters(mc:*):Array
		{
			return mc.filters;
		}
	}
}


/*使用示例
package{
       
        import flash.display.MovieClip;
        import flash.text.TextField;
        import flash.text.TextFieldAutoSize;
        import flash.text.TextFormat;
       
        import kujiukaren.createUI.FilterUtil;
       
        public class SampleMain extends MovieClip {
               
                private var _titleText:TextField;
                private var _titleText_2:TextField;
                private var _titleText_3:TextField;
               
                public function SampleMain() {
                        _titleText=new TextField();
                        _titleText.text="什么都不加";
                        _titleText.autoSize=TextFieldAutoSize.LEFT;
                        _titleText.x=150;
                        _titleText.y=50;
                       
                        _titleText_2=new TextField();
                        _titleText_2.text="设置了阴影滤镜";
                        _titleText_2.autoSize=TextFieldAutoSize.LEFT;
                        _titleText_2.x=150;
                        _titleText_2.y=100;
                       
                        _titleText_3=new TextField();
                        _titleText_3.text="设置了阴影+发光滤镜";
                        _titleText_3.autoSize=TextFieldAutoSize.LEFT;
                        _titleText_3.x=150;
                        _titleText_3.y=150;
                       
                        setTextStyle(_titleText,24,true,0xffffff);
                        setTextStyle(_titleText_2,24,true,0xffffff);
                        setTextStyle(_titleText_3,24,true,0xffffff);
                       
                        FilterUtil.cleanAllFilters();
                        FilterUtil.setDropShadow(_titleText_2,5.0,45,0x000000,1.0,5.0,5.0,1.0,3,false,false,false);
                       
                        FilterUtil.cleanAllFilters();
                        FilterUtil.setDropShadow(_titleText_3,5.0,45,0x000000,1.0,5.0,5.0,1.0,3,false,false,false);
                        FilterUtil.setGlow(_titleText_3,0xff3300,1.0,5.0,5.0,1,3,false,false);
                       
                        addChild(_titleText);
                        addChild(_titleText_2);
                        addChild(_titleText_3);
                }
               
                private function setTextStyle(txtField:TextField,size:int=12,bold:Boolean=false,color:uint=0xffffff):void{
                        var fontStyle:TextFormat=new TextFormat();
                        fontStyle.font="Microsoft YaHei";
                        fontStyle.size=size;
                        fontStyle.bold=bold;
                        fontStyle.color=color;
                       
                        txtField.setTextFormat(fontStyle);
                }
        }
       
}
 */